package br.jus.tjpe.dao;

import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import br.jus.tjpe.dominio.Parte;

@Stateless
public class ParteDaoImpl extends DaoGenericoBase<Parte> implements ParteDao {

	@SuppressWarnings("unchecked")
	public List<Parte> consultarPartes(String nome) {
		List<Parte> partes = new ArrayList<Parte>();
		EntityManager em = getEntityManager();
		StringBuffer queryString = new StringBuffer();
		queryString.append(" select pf from ParteFisica pf where pf.nome like :nome");
		queryString.append("  union");
		queryString.append(" select pj from ParteJuridica pj where pj.razaoSocial like :nome");
		
		Query query = em.createQuery(queryString.toString());
		query.setParameter("nome", "%" + nome + "%");
		partes = query.getResultList();

		return partes;
	}
}
